<?php
namespace Common\Logic\Common;

use Common\Base\LogicBase;
use Common\Model\Common\SysLogModel;

class SysLogLogic extends LogicBase
{
    public $m_sys_log;

    public function __construct()
    {
        $this->m_sys_log =  new SysLogModel();
    }

    /**
     * 得到系统日志
     *
     * @param int    $w
     * @param array  $search
     * @param string $fields
     * @param int    $page
     * @param int    $pageSize
     * @param string $by
     *
     * @return array
     */
    public function getSysLog($w=3, $search=array(), $fields='*', $page=0, $pageSize=0, $by='')
    {
        return $this->m_sys_log->getSysLog($w, $search, $fields, $page, $pageSize, $by);
    }

    /**
     * 操作日志删除
     *
     * @param int $week
     *
     * @return boolean
     */
    public function logDelete($week = 4)
    {
        $start = time() - $week*7*24*3600;
        $d = date('Y-m-d', $start);
        $where = "left(`time`, 10) <= '$d'";
        $aff = $this->m_sys_log->logDelete($where);
        if(false === $aff){
            $this->setError($this->m_sys_log->getError());
            return false;
        }
        return $aff;
    }
}